package com.huilian.iotbox.data.producer;

import com.alibaba.fastjson.JSONObject;
import com.huilian.iotbox.data.po.MessageLog;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class MessageLogRabbit {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendMessageLog(MessageLog messageLog) {
        CorrelationData correlationData = new CorrelationData(messageLog.getMessageId());
        rabbitTemplate.convertAndSend("iotbox-message-log",
                "iotbox-message-log.messageLog",
                JSONObject.toJSONString(messageLog), correlationData);
    }


    public void sendEMQXMessageToConsume(MessageLog messageLog) {
        CorrelationData correlationData = new CorrelationData(messageLog.getMessageId());
        rabbitTemplate.convertAndSend("iotBox-emqx-pubMessage",
                "iotBox-emqx-pubMessage.pubMessage",
                JSONObject.toJSONString(messageLog), correlationData);
    }

    public void sendBlueToothMessageToConsume(MessageLog messageLog) {
        CorrelationData correlationData = new CorrelationData(messageLog.getMessageId());
        rabbitTemplate.convertAndSend("iotBox-blueTooth-pubMessage",
                "iotBox-blueTooth-pubMessage.pubMessage",
                JSONObject.toJSONString(messageLog), correlationData);
    }
}
